package cn.tedu.apiday10;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

//按行读写
public class Client2 {
    public static void main(String[] args) throws IOException {
        //连接指定服务器
        Socket socket = new Socket("176.46.4.71",8000) ;
        //给服务器发送数据--out----按行PrintWriter

            OutputStream outputStream = socket.getOutputStream();
            //开始写出数据
            PrintWriter writer = new PrintWriter(outputStream);
            System.out.println("请输入想要发给服务器的东西");
            String input = new Scanner(System.in).nextLine();
            writer.println(input);//按行写出
            writer.flush();//把数据刷出去
            //开始接收数据
            InputStream inputStream = socket.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            String line = reader.readLine();//按行读取数据
            System.out.println("服务端发来的数据是" + line);



    }
}
